FILETYPE LUA

Lua filetype icon Once you have written a RiscLua program in a text editor and saved it to a file with filetype Lua, then all you have to do to run it is to doubleclick on the file's icon. Alternatively, if it is to run in a taskwindow Run in a taskwindow drag the file to TaskW's iconbar icon. The same is true for files that that have been compiled with Compile.

IMMEDIATE MODE

If you press F12 (or CTRL-F12 if you want a taskwindow), and enter the command lua at the prompt, *, you enter Lua's immediate mode, with prompt >.

*lua
Lua 5.4.2  Copyright (C) 1994-2020 Lua.org, PUC-Rio
RiscLua 84  (VFP)
> cube = "   %d^3 = %d"
> for x = 1,10 do  print (cube:format (x, x^3)) end
   1^3 = 1
   2^3 = 8
   3^3 = 27
   4^3 = 64
   5^3 = 125
   6^3 = 216
   7^3 = 343
   8^3 = 512
   9^3 = 729
   10^3 = 1000
> os.exit ( )
*
In this example a string cube is defined. The expression %d is a format-specifier. It stands for a place to be filled in by a whole number. The next line defines a for-loop with iteration-variable x. Note the different syntax from Basic's FOR construct. The body of the loop starts with the word do and is terminated by the word end. The function cube:format expects as many arguments as there are are format-specifiers in cube. Their values are substituted into the format-string to produce the value of the function. To quit immediate mode enter os.exit ( ) at the >-prompt, and you will regain the *-prompt. Immediate mode is really only useful for evaluating short expressions. It lacks the facilities needed for proper programs.

RUNNING PROGRAMS FROM OBEY FILES

You can start a RiscLua program from an Obey file by entering its pathname after the command lua. You might want to do this in a !Run file, for example. Any subsequent words on the commandline can be used in the program with the names arg[1] , arg[2] ... and so on. The pathname of the file holding the program itself is available as the value of arg[0] . This is a very convenient way of passing information into the program, not available when you just doubleclick, and means that programs can be treated like procedures with arguments given on the commandline. Using arg[0] a program can know where in the filing system it sits. That is why you will often find something like this at the start of a program:

here = (arg[0]):gsub ("%.[^%.]+$", "")
This assigns to the variable here the pathname of the directory in which the program resides. It does this by substituting with an empty string all the characters in the program's pathname from the last dot (i.e. directory-separator) to the end of the pathname. The string "%.[^%.]+$" is an example of a pattern. Patterns, though rather unreadable, allow you to manipulate text very concisely.